# -*- coding: utf-8 -*
import numpy as np

# 类别 15cls
# CLASSES = ("Domestic waste", "Construction waste", "forest_empty", "road_surface", "illegal_building",
#            "Interplanting", "Uncovered_GH", "river", "greenhouse", "Rubble",
#            "Land_cover", "Dead trees", "leaning-tree", "Gravel", "forest_empty2")

# class_name_to_id = {"_background_": 0, "Domestic waste": 1, "Construction waste": 2, "forest_empty": 3,
#                     "road_surface": 4, "illegal_building": 5, "Interplanting": 6, "Uncovered_GH": 7, "river": 8,
#                     "greenhouse": 9, "Rubble": 10, "Land_cover": 11, "Dead trees": 12, "leaning-tree": 13,
#                     "Gravel": 14, "forest_empty2": 15,
#                     }
# 5cls
CLASSES = ("forest_empty", "road_surface", "illegal_building", "river", "greenhouse", )
class_name_to_id = {"_background_": 0, "forest_empty": 1, "road_surface": 2, "illegal_building": 3, "Interplanting": 4, "river": 5,
                    "greenhouse": 6,
                    }

# 检测参数
Detector_para = {
    'config_file': '/media/glc/jack/Project_ShangHai/Flask-Detector-Shanghai-solo-15/models/solov2_up_1120_r50.py',
    'checkpoint_file': '/media/glc/jack/Project_ShangHai/Flask-Detector-Shanghai-solo-15/models/epoch_1120_r50_53.pth',
    'score_thr': 0.4,
    'save_dir': './PushStream/solo_out/',
    'simsun_path': './simsun.ttc',
    'icon': './lcon/uav.png',
    'pkl_out': './models/tmp.pkl',
    'blackimg': 'black_img.png',
}

# 推流参数
Flask_para = {'rtmpurl': "rtmp://172.30.15.91:1935/myapp/",
              'base_path': "/media/glc/Elements/project/Project_ShangHai/Flask-Detector-Shanghai-solo-15/",
              }

# TensorRT参数
Tensorrt_para = {'config': './models_TensorRT/solov2_0318_r50.py',
                 'checkpoint': './models_TensorRT/epoch_0318_r50.pth',
                 'onnx_output': './models_TensorRT/epoch_0318_r50.onnx',
                 'engine_path': './models_TensorRT/epoch_0318_r50.engine',
                 'h': 960,
                 'w': 960,
                 'numclass': 15,
                 'mode': 'fp16',
                 'pkl_out': './models_TensorRT/tensorrt.pkl',
                 }
# 后处理参数
Cls_Conf_Thre_para = {"min_area": [108, 160, 1363, 3395, 737,
                                   2993, 4084, 3549, 6055, 365,
                                   663, 152, 792, 1016, 4072],
                      "score_thresh": [0.2, 0.3, 0.12, 0.12, 0.12,
                                       0.15, 0.15, 0.3, 0.17, 0.15,
                                       0.15, 0.3, 0.2, 0.15, 0.15],  # 低阈值
                      # "score_thresh": [0.5, 0.35, 0.35, 0.4, 0.5,
                      #                  0.3, 0.25, 0.55, 0.4, 0.5,
                      #                  0.45, 0.35, 0.3, 0.3, 0.3],  # 高阈值
                      # "score_thresh": [1, 1, 1, 0.12, 1,
                      #                  1, 1, 1, 1, 1,
                      #                  1, 1, 1, 1, 1],
                      }


# 创建用于 shanghai 分割基准的标签颜色图
def create_shanghai_label_colormap():
    """创建用于 shanghai 分割基准的标签颜色图
    Returns:
        用于可视化分割结果的颜色图。
    """
    colormap = np.zeros((256, 3), dtype=np.uint8)
    colormap[0] = [0, 0, 0]
    colormap[1] = [240, 230, 140]  # Domestic waste
    colormap[2] = [251, 255, 230]  # Construction waste
    colormap[3] = [169, 192, 189]  # forest_empty 115, 112, 96
    colormap[4] = [233, 239, 237]  # road_surface
    colormap[5] = [40, 78, 83]  # illegal_building
    colormap[6] = [129, 205, 140]  # Interplanting
    colormap[7] = [177, 183, 169]  # Uncovered_GH
    colormap[8] = [179, 199, 174]  # river
    colormap[9] = [154, 167, 175]  # greenhouse
    colormap[10] = [121, 121, 118]  # Rubble
    colormap[11] = [146, 164, 171]  # Land_cover
    colormap[12] = [202, 203, 184]  # Dead trees
    colormap[13] = [101, 138, 79]  # leaning-tree
    colormap[14] = [226, 221, 215]  # Gravel
    colormap[15] = [161, 156, 158]  # forest_empty2

    # RGB->BGR
    colormap = colormap[:, [2, 1, 0]]

    return colormap
